﻿//初始化的时候，现加载第一页，数量为10，三个tab页面一起加载。
//上啦刷新之后，加载第二页，用appendHtml
mui.init({
	swipeBack:false, //启用右滑关闭功能
	keyEventBind: {
		backbutton: false  //关闭back按键监听
	}
}); 
var appendSum = 10;//每次加载数量
var pageNum = 1;//当前页数
mui.plusReady(initSomething);
function initSomething(){
	common.utils.setWhite();
	$("#tabToContact").on("tap",function(){//点击取消按钮事件
		plus.webview.close( "searchContact.html", "auto");
		common.utils.setBlue();	
	})
}

		/**
		 * 搜索
		 */
		function searchContact(){
			var search = $("#search").val();
			if(search){
				$("#loading").show();
				var jsondata = {"method":"searchContact","search":search,"appendSum":appendSum,"pageNum":pageNum};
			    mui.ajax(BaseServerAddr+'appAction.do',{
			        data:{jsondata:$.toJSON(jsondata)},
			        dataType:'json',
			        type:'post',
			        async:false,
			        timeout:10000,
			        success:function(data){
				       	if(data && data.contactlist){
				      		var clist = data.contactlist;
				      		initHtml(clist);
				      	}
			      	},
			      	error:function(xhr,type,errorThrown){
				     	//异常处理
				     	alert('服务器异常链接失败!');
			      	}
			    });
			}else{
				alert("请填写搜索关键词");
			}
			return false;
		}
		/**
		 * 拼接HTML
		 */
		function initHtml(data){
			var html = '';
			$.each(data,function(m,n){//循环遍历每个group
				html = html + '<li class="mui-table-view-cell mui-media contact_li_fortap animated fadeInRight" style="animation-delay: 0.'+m+'s;" data-id="'+data[m].ID+'">';
				html = html + '<a class="mui-navigate-right">';
				if('0' == data[m].sex){
					html = html + '<img class="mui-media-object mui-pull-left contact-person-img" src="../img/common/woman.png">';
					html = html + '<div class="mui-media-body contact-person-font girl">';
				}else{
					html = html + '<img class="mui-media-object mui-pull-left contact-person-img" src="../img/common/man.png">';
					html = html + '<div class="mui-media-body contact-person-font boy">';
				}
				html = html + data[m].name;
				html = html + '<span style="padding-left: 10px;">';
				if('0' == data[m].sex){
					html = html + '<img width="15px" height="15px" src="../img/common/girl.png"/></span>';
				}else{
					html = html + '<img width="15px" height="15px" src="../img/common/boy.png"/></span>';
				}
				html = html + '<span class="tel">';
				html = html + data[m].tel;
				html = html + '</span>'
				html = html + '</div>'
				html = html + '</a>'
				html = html + '</li>'
			})
			$("#loading").hide();
			$("#container").append(html);
			$(".contact_li_fortap").off("tap");
			$(".contact_li_fortap").on("tap",function(){
				var userid = $(this).attr("data-id");
				//	创建新页面
				var contactInfo = plus.webview.create("contactInfo.html", "contactInfo.html", {},{"userid":userid});
				//	显示新页面
				plus.webview.show(contactInfo, "slide-in-right", "350ms", function() {}, false);
				setTimeout(function(){
					plus.webview.close("searchContact.html","none",0);
				},350)
			});
		}